# leetcode: Length of Last Word | LeetCode OJ
# lintcode: (422) Length of Last Word
# Given a string s consists of upper/lower-case alphabets and empty space characters ' ',
# return the length of last word in the string.

# If the last word does not exist, return 0.

# Have you met this question in a real interview? Yes
# Example
# Given s = "Hello World", return 5.

# Note
# A word is defined as a character sequence consists of non-space characters only.

def getLastWordSize(s):
	s = s.strip()
	l = list(s)
	# 从后往前走，遇到第一个空格停下
	i = len(l) - 1
	while i >= 0 and not l[i] == ' ':
		i -=1
	return len(s[i+1:])

print(getLastWordSize(' Hello World '))
